# include <bits/stdc++.h>
using namespace std;

inline char getc() { 
    static char buf[1 << 18], *fs, *ft;
    return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}

inline int gn() { 
    register int k = 0, f = 1;
    register char c = getc();
    for(; !isdigit(c); c = getc()) if (c == '-') f = -1;
    for(; isdigit(c); c = getc()) k = k * 10 + c - '0';
    return k * f;
}

int f[102][102][102], n, m, a, b, w[102], v[102], p[102], ans;
vector <int> box[12];

int main() { 
# ifndef LOCAL
    freopen("soultap.in", "r", stdin);
    freopen("soultap.out", "w", stdout);
# else 
    freopen("in", "r", stdin);
# endif
    n = gn(), m = gn(), a = gn(), b = gn();
    for(int t, i = 1; i <= n; i++) { 
        w[i] = gn(), v[i] = gn(), t = gn(), p[i] = gn();
        box[t].push_back(i);
    }
    for(int i = 1; i <= m; i++) { 
        for(int j = 0; j <= a; j++) { 
            for(int k = 0; k <= b; k++) { 
                f[i][j][k] = f[i - 1][j][k];
            }
        }
        for(int o = 0; o < box[i].size(); o++) { 
            int tmp = box[i][o];
            for(int j = w[tmp]; j <= a; j++) { 
                for(int k = v[tmp]; k <= b; k++) { 
                    f[i][j][k] = max(f[i][j][k], f[i - 1][j - w[tmp]][k - v[tmp]] + p[tmp]);
                    ans = max(ans, f[i][j][k]);
                }
            }
        }
    }
    printf("%d\n", ans);
}
